/* File Info
 * Author:      李佳乐
 * CreateTime:  2024/1/4 08:37:27
 * LastEditor:  李佳乐
 * ModifyTime:  2024/1/4 09:00:38
 * Description: explict关键字的使用禁止隐式转换: class explictCpp eA = 2;
 */
#ifndef __EXPLICT__
#define __EXPLICT__

#include <iostream>

class non_explictCpp
{
private:
    int data;

public:
    non_explictCpp(int a) : data(a){};
    void showData() { std::cout << "the data of this non_explictCpp is " << this->data << std::endl; }
};

class explictCpp
{
private:
    int data;

public:
    explicit explictCpp(int a) : data(a){};
    void showData() { std::cout << "the data of this explictCpp is " << this->data << std::endl; }
};

int main()
{
    /*** 构造函数没有加explict关键字 ****/
    class non_explictCpp neA(1);
    class non_explictCpp neB = 2;
    /*** 构造函数前加explict关键字 ****/
    // class explictCpp eA = 2; //这就是隐式转换，在构造函数上加了explict 关键字就禁止隐式转换
    class explictCpp eB(3); // 这种显式的转换是可以的
    /*********************************/

    neA.showData();
    neB.showData();
    eB.showData();
}

#endif
